import Mock from 'mockjs2'
import { builder, getQueryParameters } from '../util'

const Random = Mock.Random

const memberSearch = (options) => {
    const parameters = getQueryParameters(options)

    console.log(parameters)

    const result = []
    const status = parseInt(parameters.status) || 1

    result.push({
        id: 0,
        uuid: Random.guid(),
        nickname: 'admin',
        mobile: '137****6839',
        avatar: Random.image('64x64'),
        topic_count: Random.natural(10, 100),
        register_ip: Random.ip(),
        register_time: Random.datetime(),
        last_login_ip: Random.ip(),
        last_login_time: Random.datetime(),
        status: status,
        group: {
            group_id: '1',
            name: '管理员'
        }
    })

    for (let index = 1; index < 6; index++) {
        result.push({
            id: index,
            uuid: Random.guid(),
            nickname: Random.first(),
            mobile: '137****6839',
            avatar: Random.image('64x64'),
            topic_count: Random.natural(10, 100),
            register_ip: Random.ip(),
            register_time: Random.datetime(),
            last_login_ip: Random.ip(),
            last_login_time: Random.datetime(),
            status: status,
            group: {
                group_id: 2,
                name: '会员'
            }
        })
    }

    return builder(result)
}

const role = () => {
    return builder({ data: [
        {
            group_id: 1,
            name: '管理员',
            status: 1
        }, {
            group_id: 2,
            name: '运维',
            status: 1
        }, {
            group_id: 3,
            name: '会员',
            status: 1
        }
    ] })
}

Mock.mock(/\/member\/search/, 'post', memberSearch)
Mock.mock(/\/member\/role/, 'get', role)
